dhcpv4: dhcpv4_fr_rand_delay() fixups
authorDavid Härdeman <[email protected]>
Wed, 24 Sep 2025 13:44:13 +0000 (15:44 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Tue, 7 Oct 2025 09:01:51 +0000 (11:01 +0200)
Move constants to dhcpv4.h, and make their names more descriptive. Also, use
abs() instead of labs(), since "msecs" is an int.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/266
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/dhcpv4.c
src/dhcpv4.h

index 15425a5b506833af0f88a4df41ff33101bd02d65..25fcdb6c22f71fa8bb6f5c894b7b0fb7d09f94ba 100644 (file)
@@ -280,13 +280,11 @@ static void dhcpv4_fr_delay_timer(struct uloop_timeout *event)
 
 static void dhcpv4_fr_rand_delay(struct dhcp_assignment *a)
 {
-#define MIN_DELAY   500
-#define MAX_FUZZ    500
        int msecs;
 
        odhcpd_urandom(&msecs, sizeof(msecs));
 
-       msecs = labs(msecs)%MAX_FUZZ + MIN_DELAY;
+       msecs = abs(msecs) % DHCPV4_FR_MAX_FUZZ + DHCPV4_FR_MIN_DELAY;
 
        uloop_timeout_set(&a->fr_timer, msecs);
        a->fr_timer.cb = dhcpv4_fr_delay_timer;
index 7db5c521ead42a6adb2a8f408cf65ffeb4eb419d..d54aedbfb39687857fbc77877788463e9f4e23d8 100644 (file)
@@ -21,6 +21,9 @@
 
 #define DHCPV4_MIN_PACKET_SIZE 300
 
+#define DHCPV4_FR_MIN_DELAY    500
+#define DHCPV4_FR_MAX_FUZZ     500
+
 enum dhcpv4_op {
        DHCPV4_BOOTREQUEST = 1,
        DHCPV4_BOOTREPLY = 2